import { _decorator, Component, Node, RichText, Label } from 'cc';
import { VIDEO_MSG, VIDEO_STATUS } from '../../ccc3-framework-core/const/MSG';
import { httpUtil } from '../../ccc3-framework-core/framework/modules/httpUtil';
import { memoryConfig } from '../../ccc3-framework-core/framework/modules/memoryConfig';
import { uiManager } from '../../ccc3-framework-core/framework/modules/uiManager';
import { UiForm } from '../../ccc3-framework-core/framework/ui/uiForm';
import { platformUtil } from '../../ccc3-framework-core/platform/platformUtil';
import { LeveLCfg } from '../../sheets/vo/LeveLCfg';
import TaskProxy from '../../3rd/Guyu/Scripts/[业务]/广告任务/Controller/TaskProxy';
const { ccclass, property } = _decorator;

@ccclass('tooltipForm')
export class tooltipForm extends UiForm {

    @property(Node)
    btnVideo: Node = null;

    @property(Node)
    btnCancel: Node = null;

    @property(Label)
    txtTooltip: Label = null;


    start() {
        this.bindTouchEnd(this.btnVideo, this.onVideo2)
        this.bindTouchEnd(this.btnCancel, this.hideForm)
    }

    onEnable() {
        this.btnVideo.active = true;
        this.txtTooltip.string = `需要过关提示吗？`;
    }

    // private onVideo() {
    //     httpUtil.reportVideoStart("获取提示");
    //     platformUtil.currentPlatform.showVideo(res => {
    //         switch (res) {
    //             case VIDEO_STATUS.END:
    //                 httpUtil.reportVideoFinish("获取提示");
    //                 let cfg = LeveLCfg.getCfgByLevel(memoryConfig.instance.level + 1);
    //                 this.txtTooltip.string = `${cfg.tips}`;
    //                 this.btnVideo.active = false;
    //                 break;
    //             case VIDEO_STATUS.ERR:
    //                 uiManager.showToast(VIDEO_MSG.ERR);
    //                 break;
    //             case VIDEO_STATUS.NOTEND:
    //                 uiManager.showToast(VIDEO_MSG.NOTEND);
    //                 break;
    //             default:
    //                 break;
    //         }
    //     })
    // }

    private async onVideo2() {
        let taskConfig = TaskProxy.inst.taskConfig;
        let adUnitId = taskConfig.m_CommmonRewardID;
        let ad = Guyu.AdFactory.getAD({
            adUnitId: adUnitId,
            init: true,
        });
        let { success, errMsg } = await ad.playAd({
            showError: true,
            showLoading: true,
        });
        if (!success) {
            uiManager.showToast(errMsg);
            return;
        }
        let cfg = LeveLCfg.getCfgByLevel(memoryConfig.instance.level + 1);
        this.txtTooltip.string = `${cfg.tips}`;
        this.btnVideo.active = false;
    }

    update(deltaTime: number) {

    }
}

